<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class ClubController extends AdminbaseController{
	
	// 微信用户列表
	public function index(){
		$Club = M('Club');
		$list = $Club->order('add_time desc')->select();
        $this->assign('list',$list);
        $this->display();
	}
	//添加球房
	public function add(){
		if(IS_POST){
		    $Club = M('Club');
			$club_info['name']             = I('post.name');
			$club_info['city']             = I('post.city');
			$club_info['address']          = I('post.address');
			$club_info['manager']          = I('post.manager');
	        $club_info['mobile']           = I('post.mobile');
	        $club_info['table_count']      = I('post.table_count');
	        
	        $club_info['add_time']         = $club_info['update_time'] = time();
	       
	 
	        if($Club->where('mobile='.$club_info['mobile'])->find()){
	            $this->error("添加失败，该球房已经存在！");
	        }else{
				if($result = $Club->add($club_info)){
					$this->success("添加成功！", U("Club/index"));
				}else{
					$this->error("添加失败！");
				}
		    }
		}

        $this->display();
	}
	//编辑球房
	public function edit(){
		$id   = I('get.id');
		$Club = M('Club');
        if(IS_POST){
            $where['id']                   =(int)$_POST['id'];
			
			$club_info['name']             = I('post.name');
			$club_info['city']             = I('post.city');
			$club_info['address']          = I('post.address');
			$club_info['manager']          = I('post.manager');
	        $club_info['mobile']           = I('post.mobile');
	        $club_info['table_count']      = I('post.table_count');
	        
	        $club_info['update_time']      = time();
            $result = $Club->where($where)->save($club_info);
			if($result === 0 || $result){
		
				$this->success("修改成功！", U("Club/index"));
			}else{
				$this->error("修改失败！");
			}
				
        }
        
        $club_info = $Club->where('id = '.$id)->find();
		$this->assign('club_info',$club_info);
		$this->display();
        
	}


	//获取球房的名称
	public function get_club_name(){
		$id             = I('get.id');
		$data['status'] = 0;
		if($data['name'] = M('Club')->where('id = '.$id)->getField('name')){
			$data['status'] = 1;
		}
		$this->ajaxReturn($data);
	}

}